<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>商家收款</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../css/style.css"/>
		<link rel="stylesheet" href="../css/iconfont.css" />
		<link rel="stylesheet" href="../css/wallet.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" href="JavaScript:history.go(-1)"></a>
		    <h1 class="mui-title">商家收款</h1>
		</header>
		<div class="mui-content yongj_content">
			 <ul class="bank_list">
		    	<li class="clearfix">
		    		<label style="width:35%;">收款账号</label>
		    		<input style="width:65%;"type="text" id="bank_name" placeholder="请输收款人账号" />
		    		<input  type="hidden" id="agent_id" value="" />
		    		<input  type="hidden" id="store_balance" value="" />
		    	</li>
		    	<li class="clearfix">
		    		<label style="width:35%;">付款人账号</label>
		    		<input style="width:65%;" type="text" id="bank_num" placeholder="请输入付款人账号" />
		    		<input  type="hidden" id="credit2" value="" />
		    </ul>
			<div class="tixian_pri">
		    	<p>收款金额</p>
		    	<p class="tixian_prinum clearfix">
		    		<label>¥</label>
		    		<input type="text" id="pay_moeny" placeholder="请输入收款金额" />
		    	</p>
		    </div>
		    <div class="wallet_btn" id="btn"><a href="#">确认</a></div>
		</div>
	</body>
</html>
<script src="../js/mui.min.js"></script>

<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/layer/layer.min.js"></script>
<script type="text/javascript" src="../js/app.js"></script>
<script type="text/javascript">
	//获取收款人账号、付款人账号
	$.ajax({
			url: APP.api_url + 'wallet/userInfo',
			data: {
				uid			: getUid(),
				token		: get_token,
			},
			//成功了的回调，并且带有返回值
			success: function(data) {
				if(data.code == 200) {
					var shopInfo = data.data[1];
					$("#bank_name").val(shopInfo.store_tel); 
					$("#agent_id").val(shopInfo.id); 
					$("#store_balance").val(parseInt(shopInfo.store_balance)); 
					var userInfo = data.data[0];					//alert(json);
					$("#bank_num").val(userInfo.mobile);
					$("#credit2").val(userInfo.credit2);
				}else{
					console.log(data.msg);
				}
			}
		})
	
	//收款
	var btn = $('#btn');
	btn.click(function() {
		var bank_name = $("#bank_name").val();
		var bank_num = $("#bank_num").val();
		var pay_money=$('#pay_moeny').val();
		if(bank_name.trim() == '') {
			layer.msg('收款不能为空');
			return;
		}
		
		if(bank_num.trim() == '') {
			layer.msg('付款账号不能为空');
			return;
		}
		if(bank_name.trim()==bank_num.trim()){
			layer.msg('付款账号与付款账号不能相同');
			return;
		}
		if(pay_money == '') {
			layer.msg('收款金额不能为空');
			return;
		}
		
		btn.disabled = true;
		var shop_total_balance=$("#store_balance").val()+pay_money;//商家总余额
		var user_total_credit=$("#credit2").val()-pay_money;//用户总余额
		//写入数据库
		$.ajax({
			//请求的url
			url: APP.api_url + 'wallet/shop_shoukuan',
			//请求的过程中传递过去的参数 json
			data: {
				agent_id	: $('#agent_id').val(),
				store_balance:shop_total_balance,
				bank_name	: bank_name,
				bank_num 	: bank_num,
				pay_moeny	: pay_money,
				uid			: getUid(),
				credit2     :user_total_credit,
				token		: get_token
			},
			//成功了的回调，并且带有返回值
			success: function(data) {
				layer.msg(data.msg);
				if(data.code == 200) {
					layer.msg('收款成功！', {
						  time: 2000 //2秒关闭（如果不配置，默认是3秒）
						}, function(){
							location.href="index.html";
						});
				}else{
					console.log(data.msg);
				}
			}
		})
	});
</script>